/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-07-03 16:20:52
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-07-22 16:59:04
 * @FilePath: \linePatrol\vue-element-plus-admin\src\hooks\PublicFun.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//数组扁平化
export const flatData = (data, parentId = undefined) => {
  return data.reduce((prev, curr) => {
    if (parentId != undefined) {
      Object.assign(curr, {
        parentId: parentId
      })
    }
    prev.push(curr)
    if (curr.children !== undefined && curr.children.length > 0) {
      prev.push(...flatData(curr.children, curr.id))
    }
    return prev
  }, [])
}
export function DateFormat(value: any) {
  const padDate = function (value) {
    return value < 10 ? '0' + value : value
  }
  const date = new Date(value)
  const year = date.getFullYear()
  const month = padDate(date.getMonth() + 1)
  const day = padDate(date.getDate())
  const hour = padDate(date.getHours())
  const min = padDate(date.getMinutes())
  const sec = padDate(date.getSeconds())
  return `${year}-${month}-${day} ${hour}:${min}:${sec}`
}
export function NowDate() {
  const date = new Date()
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const min = date.getMinutes()
  const sec = date.getSeconds()
  return `${year}${month}${day}${hour}${min}${sec}`
}
